// pages/ChangePassword/ChangePassword.js
var that,
  api = new (require('../../utils/api.js')),
  headimg = api.getimgurl(),
  app = getApp(),
  util = new (require('../../utils/util.js'));
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isconfirm:!1,
    phone:'',
    oldPwd:"",
    newPwd:'',
    confirmPwd:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that=this;
    that.getdata()
  },
  getdata(){
    api.systemforgethelp(res=>{
      if(res.data.code==0){
        that.setData({phone:res.data.entity.data.phone})
      }
    })
  },
  freeTell: function(){
    let {phone}=that.data
    wx.makePhoneCall({
      phoneNumber: phone,
    })
  },
  inputtap(e){
    let { value } = e.detail,{prop}=e.currentTarget.dataset
    that.setData({[prop]:value})
  },
  modifypassword(){
    let {oldPwd,newPwd,confirmPwd}=that.data,err=''
    if(confirmPwd==''||confirmPwd.length!=6)err='请确认新密码'
    if(newPwd==''||newPwd.length!=6)err='请输入新密码'
    if(oldPwd==''||oldPwd.length!=6)err='请输入旧密码'
    if(err!=''){
      wx.showModal({
        content:err,
        showCancel:!1,
      })
      return;
    }
    api.useralterpwd({oldPwd,newPwd,confirmPwd},res=>{
      if(res.data.code==0){
        that.setData({ isconfirm:!0})
        setTimeout(function () {
          wx.navigateBack()
        }, 1000)
      }else{
        wx.showToast({
          title: res.data.message,
          icon: 'none'
        })
      }
    })
  },
  cancel(){
    that.setData({ isconfirm:!1})
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})